package com.guli.gulimall.member.service.impl;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.guli.common.utils.HttpUtils;
import com.guli.common.vo.WeiboAccessVo;
import org.apache.http.HttpResponse;
import org.apache.http.util.EntityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.guli.common.utils.PageUtils;
import com.guli.common.utils.Query;

import com.guli.gulimall.member.dao.MemberDao;
import com.guli.gulimall.member.entity.MemberEntity;
import com.guli.gulimall.member.service.MemberService;


@Service("memberService")
public class MemberServiceImpl extends ServiceImpl<MemberDao, MemberEntity> implements MemberService {
    @Autowired
    private MemberDao memberDao;

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<MemberEntity> page = this.page(
                new Query<MemberEntity>().getPage(params),
                new QueryWrapper<MemberEntity>()
        );

        return new PageUtils(page);
    }

    @Override
    public MemberEntity weiboLogin(WeiboAccessVo weiboAccessVo) {
        // 判断是否注册过
        MemberEntity memberEntity = memberDao.selectOne(new QueryWrapper<MemberEntity>().eq("access_token", weiboAccessVo.getAccess_token()));
        if (memberEntity != null) {
            // 用户注册过
        } else {
            // 用户没有注册过
        }
        return null;
    }

    public static void main(String[] args) throws Exception {
        HashMap<String, String> map = new HashMap<>();
        map.put("access_token","2.00DsI1mGWZH18Ba785185c298wgU9B");
        map.put("uid","6210861783");
        HttpResponse httpResponse = HttpUtils.doGet("https://api.weibo.com", "/2/users/show.json", "get", null, map);
        String s = EntityUtils.toString(httpResponse.getEntity());
        //获取到查询结果的json对象
        JSONObject jsonObject = JSON.parseObject(s);
    }

}